F
F
o
o
r
r
m
m
a
a
t
t
t
t
i
i
n
n
g
g
This example shows how to apply different formatting to the Text View.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.ui.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.text.font.*
import androidx.compose.ui.text.style.*
import androidx.compose.ui.unit.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Stack(Modifier.fillMaxSize()) {
Text(
text = "Text",
modifier = Modifier
.align (Alignment.Center)
.fillMaxWidth()
.padding (25.dp)
.border (2.dp, Color.Magenta),
color = Color.Red,
fontSize = 50.sp,
fontStyle = FontStyle.Italic,
fontWeight = FontWeight.Bold, //Bold, Thin, [W100, W900]
fontFamily = FontFamily.Cursive, //Default, Cursive, Sanserif, Serif, Monospace
textDecoration = TextDecoration.Underline, //Underline, Linethrough
textAlign = TextAlign.Left //Left, Center, Right, Justify
)
}
}
}
}
Output
4
4
.
.
2
2
C
C
o
o
n
n
t
t
a
a
i
i
n
n
e
e
r
r
V
V
i
i
e
e
w
w
s
s
I
I
n
n
f
f
o
o
Container Views are used to put other Views inside them to be able to easier organize them and navigate through them.
Column Row
LazyColumnFor LazyRowFor
ScrollableColumn ScrollableRow
Stack Surface